package com.lightswitch.smarttranslator.webservice;

import com.lightswitch.smarttranslator.processing.SmartTranslatorProcessor;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.sourceforge.tess4j.TesseractException;
import org.apache.thrift.TException;

/**
 * 
 * @author HieuPham
 */
public class ServiceProcessor implements SmartTranslatorService.Iface {

    @Override
    public __TranslateResponsingModel processImage(__TranslateSendingModel sendingModel) throws TException {
        try {
            String languageOrigin = sendingModel.get_languageOrigin();
            String languageResult = sendingModel.get_languageResult();
            SmartTranslatorProcessor processor = SmartTranslatorProcessor.getInstanceOrInitProcessor(languageOrigin, languageResult);
            return processor.process(sendingModel._imageBytes, sendingModel._ocrMode);
        } catch (TesseractException ex) {
            Logger.getLogger(ServiceProcessor.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(ServiceProcessor.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }
}
